package com.weasing.res.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.weasing.res.dao.IWxAdminDao;
import com.weasing.res.domain.WxAdmin;
import com.weasing.res.service.IWxAdminService;
import com.weasing.res.service.base.impl.BaseServiceImpl;
import com.weasing.res.utils.MD5Utils;
@Service
@Transactional
public class WxAdminServiceImpl extends BaseServiceImpl<WxAdmin>
		implements IWxAdminService {
	@Autowired
	private IWxAdminDao wxAdminDao;

	// 登录
	public WxAdmin login(WxAdmin model) {
		// TODO Auto-generated method stub
		// 对密码进行加密
		String md5 = MD5Utils.md5(model.getPassword());
		return wxAdminDao.findUserByUsernameAndPassword(model.getUsername(),
				md5);
	}

	/**
	 * 修改功能
	 */
	public void editPasswordForm(String id, String password) {
		// TODO Auto-generated method stub
		password = MD5Utils.md5(password);
		wxAdminDao.ececuteUpdate("editPasswordForm", password, id);
	}

	/**
	 * 注册功能实现
	 */
	@Override
	public void register(WxAdmin model) {
		// 加密密码
		String password = MD5Utils.md5Double(model.getPassword());
		model.setPassword(password);
		wxAdminDao.save(model);
	}

	// 修改密码
	@Override
	public void editPasswordForm(Integer id, String password) {
		password = MD5Utils.md5Double(password);
		wxAdminDao.ececuteUpdate("editPasswordForm", password, id);
	}

	/**
	 * 通过username找对象 用作判断重复用户名
	 * @return 可以用   true    重复不可用  false
	 */

	public Boolean checkUserName(String username) {

		Boolean b = false;
		WxAdmin wxAdmin = wxAdminDao.findUserByUsername(username);
		if(null == wxAdmin ){
			b = true;
		}
		return b;
	}

	/**
	 * 更新用户
	 */
	// 修改密码
	@Override
	public void update(WxAdmin model) {
		wxAdminDao.update(model);
	}
	/**
	 * 
	 */
	public List<WxAdmin> findAllAndRole(){

		return wxAdminDao.findAllAndRole();
	}
}
